<?php
/**
 * PHP Mysql connection object, singleton pattern
 */
class dbHandler {
        private $dbuser = "pless84";
        private $dbPass = "Nerd84";
        private $dbHost = "mysql10.gigahost.dk";
        private $dbName = "pless84_schedule";
	private static $Instance;

	private function __construct() 	{
		mysql_connect($this->dbHost, $this->dbuser, $this->dbPass) or die("Problem connection to the database");
                mysql_select_db($this->dbName) or die("Problem selecting the database");
        }

        /**
         * Returns an object of the database connection
         * @return Mysql Connection object
         */
	public static function getInstance()	{
		if (!self::$Instance)
		{
			self::$Instance = new dbHandler();
		}
		return self::$Instance;
	}

	/**
         * Excutes a query with no need the returning data.
         * DML&DDL queries to be used:
         * CREATE, ALTER, DROP, UPDATE, INSERT, DELETE, TRUNCATE
         * @param $sql - THe sql string to be executed
         * @return Returns true if query was executed succesfully
         */
	public function oneWayQuery($sql){
		$done = false;
                if(mysql_query($sql) or die(mysql_error())){
                    $done = true;
                }
	}
        /**
         * Executes an SQL query with a need for returning data.
         * DML queries to be used:
         * SELECT
         * @param String $sql
         * @return $result - The resultset of the queri
         */
        public function query($sql){
            $result = mysql_query($sql) or die(mysql_error());
            if($result != null){
                return $result;
            }
        }
}
?>